﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vowei.Core.Models;

namespace Vowei.Core
{
    public static class TableMeta
    {
        public static bool IsNew<T>(this T item) where T : INamedTable
        {
            return IsIdEmpty(item);
        }

        public static bool IsIdEmpty<T>(this T item) where T : INamedTable
        {
            return item.ID.CompareTo(Guid.Empty) == 0;
        }

        public static bool IsIdEmpty(Guid id)
        {
            return id.CompareTo(Guid.Empty) == 0;
        }

        public static void FillDefaultProperties<T>(this T tobeEditing)
            where T : ISupportDefaultProperties, INamedTable
        {
            if (tobeEditing == null)
                throw new ArgumentException("tobeEdit");

            tobeEditing.ID = Guid.NewGuid();
            tobeEditing.OpenDate = DateTime.Now;
            tobeEditing.LastModified = DateTime.Now;
        }
    }
}
